﻿using System;
using System.Collections.Generic;
using System.Linq;
using Domain.Entity;

namespace QQWBDao
{
    public class QQAcountDao
    {
        /// <summary>
        /// 获取启用了的账号
        /// </summary>
        /// <returns></returns>
        public static List<QQAcount> GetEnabledAcountForWB()
        {
            using (var db = new DBDataContext())
            {
                return db.QQAcount.Where(x=>x.EnableForWB).ToList();
            }
        }
        public static List<QQAcount> GetIsLoginAcountForWB()
        {
            using (var db = new DBDataContext())
            {
                return db.QQAcount.Where(x=>x.IsLoginForWB).ToList();
            }
        }
        public static void SetLoginStateForWB(string qq, bool islogin)
        {
            using (var db = new DBDataContext())
            {
                var ret = db.QQAcount.FirstOrDefault(x => x.QQ == qq);
                ret.IsLoginForWB = islogin;
                if (islogin)
                    ret.LastLoginForWB = DateTime.Now;
                db.SubmitChanges();
            }
        }

        public static bool SetQQAcountHasVisitedAddForWB(string qq)
        {
            using (var db = new DBDataContext())
            {
                var ret = db.QQAcount.FirstOrDefault(x => x.QQ == qq);
                ret.VisitedTimesForWB ++;
                db.SubmitChanges();
                return true;
            }
        }
        public static bool SetAllQQAcountVisiteTimesForWB(int hasvisite)
        {
            using (var db = new DBDataContext())
            {
                db.ExecuteCommand("UPDATE dbo.QQAcount SET VisitedTimesForWB=" + hasvisite);
                db.SubmitChanges();
                return true;
            }
        }
        public static bool SetAllQQAcountMaxVisiteTimesForWB(int maxvisite)
        {
            using (var db = new DBDataContext())
            {
                db.ExecuteCommand("UPDATE dbo.QQAcount SET MaxVisiteTimesForWB=" + maxvisite);
                db.SubmitChanges();
                return true;
            }
        }
        public static bool SetQQAcountHasVisiteTimesForWB(int visite,string qq)
        {
            using (var db = new DBDataContext())
            {
                var q = db.QQAcount.FirstOrDefault(x => x.QQ == qq);
                q.VisitedTimesForWB = 0;
                db.SubmitChanges();
                return true;
            }
        }
    }
}
